<template>
  <div class="ag-slider-box">
    <!-- <i class="iconfont agcim-jindutiaojian" @click="remove()"></i> -->
    <p class="icon-style" @click="remove()">
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#agcim-jindutiaojian"></use>
      </svg>
    </p>
    <div class="box">
      <el-slider
        v-model="formatValue"
        :min="min"
        :max="max"
        :step="step"
        :show-tooltip="false"
        @input="change"
        :key="key"
        :disabled="disabled"
      >
      </el-slider>
      <input
        type="text"
        class="input"
        v-model="inputNumber"
        @change="changeInput()"
        ref="input"
      />
    </div>
	<p class="icon-style" @click="add()">
      <svg class="icon" aria-hidden="true">
        <use xlink:href="#agcim-jindutiaojia"></use>
      </svg>
    </p>
  </div>
</template>
<script>
export default {
  props: {
    min: {
      type: Number,
      default: 0,
    },
    max: {
      type: Number,
      default: 100,
    },
    step: {
      type: Number,
      default: 1,
    },
    value: {
      type: Number,
      default: 0,
    },
    disabled: {
      type: Boolean,
    },
    fixedNum: {
      type:Number,
      default:1
    }
  },
  data() {
    return {
      formatValue: 0,
      key: 1,
      inputNumber: 0,
    };
  },
  mounted() {
    this.formatValue = this.value;
    this.inputNumber = this.formatValue;
  },
  methods: {
    remove() {
      let num = this.formatValue - this.step;
      if (num < this.min) {
        num = this.min;
      }
      this.formatValue = Number(num.toFixed(this.fixedNum));
    },
    add() {
      let num = this.formatValue + this.step;
      if (num > this.max) {
        num = this.max;
      }
      this.formatValue = Number(num.toFixed(this.fixedNum));
    },
    changeInput() {
      this.key++;
      this.formatValue = Number(this.inputNumber);
    },
    change() {
      this.$emit("onChange", this.formatValue);
    },
  },
  watch: {
    formatValue(val, oldVal) {
      this.inputNumber = val.toFixed(this.fixedNum);
      let dom = this.$refs.input;
      let left = ((val - this.min) * 100) / (this.max - this.min);
      dom.style.left = left + "%";
      this.$emit("input", this.formatValue);
    },
  },
};
</script>
<style scoped>
.ag-slider-box {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.ag-slider-box i {
  font-size: 16px;
  color: #1e90ff;
}
.ag-slider-box i:before {
  background: #fff;
  border-radius: 50%;
}

.ag-slider-box .box {
  position: relative;
  width: 100%;
  margin: 0 14px;
}

.ag-slider-box input {
  position: absolute;
  top: 0;
  left: 50%;
  width: 40px;
  transform: translate(-20px, -20px);
  text-align: center;
  border-radius: 2px;
  box-sizing: border-box;
  border: 1px solid #1e90ff;
  background: #fff;
  outline: none;
  border: none;
}
.ag-slider-box input {
  border: 1px solid #1E90FF;
  top: 8px;
  width: 42px;
  height: 20px;
  background: #fff;
  color: #000;
  font-size: 5px;
}
::v-deep .el-slider {
  width: 100%;
}


.icon-style{
	font-size: 16px;
	cursor: pointer;
}
.agcim-jindutiao-:before .agcim-a-jindutiao:before {
  background: #fff;
  border-radius: 50%;
}
</style>
